package com.guochuang.yunwang.promanager.config;


import com.guochuang.yunwang.promanager.exception.AccessForbiddenException;
import com.guochuang.yunwang.promanager.exception.ParamException;
import com.guochuang.yunwang.promanager.exception.ProjectAssignException;
import com.guochuang.yunwang.promanager.utils.ProjectConstant;
import com.guochuang.yunwang.promanager.utils.ResultEntity;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 *
 * @author hk
 */
@ControllerAdvice
public class ProjectExceptionResolver {

    @ExceptionHandler(value = {ParamException.class})
    @ResponseBody
    public ResultEntity resolveroParamException(ParamException e) {

        ResultEntity<Object> resultEntity = ResultEntity.failed(e.getMessage());

        return resultEntity;
    }


    @ExceptionHandler(value = {ProjectAssignException.class})
    @ResponseBody
    public ResultEntity resolveroProjectAssignException(ProjectAssignException e) {

        ResultEntity<Object> resultEntity = ResultEntity.failed(e.getMessage());

        return resultEntity;
    }

    @ExceptionHandler(value = {AccessForbiddenException.class})
    @ResponseBody
    public ResultEntity resolveroAccessForbiddenException(AccessForbiddenException e) {

        ResultEntity<Object> resultEntity = ResultEntity.failed(e.getMessage());

        return resultEntity;
    }

    @ExceptionHandler(value = {AuthorizationException.class})
    @ResponseBody
    public ResultEntity resolverAuthorizationException(AuthorizationException e){
        ResultEntity<Object> failed = ResultEntity.failed(ProjectConstant.AUTH_PERMISSION_FAILED);

        return failed;
    }

}
